﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Citizenships", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(Citizenships))]
    public class CitizenshipsSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ICitizenships clazz;
        
        public CitizenshipsSerializer(ICitizenships clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Citizenship");
            if (clazz.Citizenship!=null) {
                global::Xtee.Core.SerializationMetadata metaCitizenship = this.GetMetaData(clazz.Citizenship);
                Writer.WriteTypeAttribute(metaCitizenship.TypeQualifiedName.Namespace, metaCitizenship.TypeQualifiedName.Name);
                metaCitizenship.NewSerializer(clazz.Citizenship).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Citizenship");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Citizenship") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Citizenships>Citizenship");
                }
                global::Xtee.Core.SerializationMetadata metaCitizenship = this.GetMetaData<Citizenships.ICitizenshipType>(Reader, ">>Citizenships>Citizenship", "http://producers.rr.xtee.riik.ee/producer/rr");
                clazz.Citizenship = metaCitizenship.NewEntity<Citizenships.ICitizenshipType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Citizenship");
                    metaCitizenship.NewSerializer(clazz.Citizenship).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Citizenships>Citizenship", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>Citizenships>Citizenship", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(Citizenships.CitizenshipType))]
        public class CitizenshipTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Citizenships.ICitizenshipType clazz;
            
            public CitizenshipTypeSerializer(Citizenships.ICitizenshipType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("RiigiKood");
                if (clazz.RiigiKood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RiigiKood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RiigiKood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("RiigiNimi");
                if (clazz.RiigiNimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RiigiNimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RiigiNimi");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="RiigiKood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>Citizenships>Citizenship>RiigiKood");
                    }
                    clazz.RiigiKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("RiigiKood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>Citizenships>Citizenship>RiigiKood", Reader.LocalName);
                }
                if (Reader.LocalName=="RiigiNimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>Citizenships>Citizenship>RiigiNimi");
                    }
                    clazz.RiigiNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("RiigiNimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>Citizenships>Citizenship>RiigiNimi", Reader.LocalName);
                }
            }
        }
    }
}
